<?php
/**
 * Created by PhpStorm.
 * User: 33kuai
 * Date: 2020/2/4
 * Time: 21:05
 */

namespace frontend\modules\demo\controllers;


use yii\web\Controller;
use Yii;
class SecurityController extends Controller
{

    public function actionIndex(){

        $security = YIi::$app->security;
        $password = $security->generateRandomString();
        $hash = Yii::$app->getSecurity()->generatePasswordHash($password);

        print_r($hash);

      echo PHP_EOL;
        $verify = $security->validatePassword($password,$hash);

        var_dump($verify);
    }


    public function actionCrypt(){


        $security = YIi::$app->security;
        $key = $security->generateRandomString();

        $data = 'woshisunbo';

        $enData = $security->encryptByPassword($data,$key);

        print_r($enData);
        $data2 = $security->decryptByPassword($enData,$key);

        print_r($data2);
        die;


    }
}